package cn.edu.cuit.elena.db.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;
import java.util.Map;

import cn.edu.cuit.elena.db.DataSource;
import cn.edu.cuit.elena.db.DataSourceException;

public class BaseDao
    implements AccessDataModel
{

    private DataSource dataSource;
    private Connection connection;

    public BaseDao(DataSource dataSource)
    {
        this.dataSource = dataSource;
    }

    public void update( String sql )
    {
        connection = dataSource.getConnection();

        try
        {
            Statement statement = connection.createStatement();
            statement.executeUpdate( sql );
        }
        catch( SQLException e )
        {
            throw new DataSourceException( e.getMessage() );
        }
        finally
        {
            dataSource.returnConnection( connection );
        }
    }

    public ResultSet query( String sql )
    {
        connection = dataSource.getConnection();

        try
        {
            Statement statement = connection.createStatement();
            return statement.executeQuery( sql );
        }
        catch( SQLException e )
        {
            throw new DataSourceException( e.getMessage() );
        }
        finally
        {
            dataSource.returnConnection( connection );
        }
    }

    public Map<?,?> insert( String instruction, Map<?,?> paramMap )
    {
        return null;
    }

    public Map<?,?> update( String instruction, Map<?,?> paramMap )
    {
        return null;
    }

    public Map<?,?> del( String instruction, Map<?,?> paramMap )
    {
        return null;
    }

    public Map<?,?> queryForMap( String instruction )
    {
        //TODO
        return null;
    }

    public Map<?,?> queryForMap( String instruction, Object paramObject )
    {
        //TODO
        return null;
    }

    public List<?> queryForList( String instruction, int paramInt1, int paramInt2 )
    {
        //TODO
        return null;
    }

    public List<?> queryForList( String instruction, Object paramObject, int paramInt1, int paramInt2 )
    {
        //TODO
        return null;
    }

    public List<?>  queryForList( String instruction, Object paramObject )
    {
        //TODO
        return null;
    }

    public List<?>  queryForList( String instruction )
    {
        //TODO
        return null;
    }

}
